home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 016a / gofer221.zip / APPX_A < prev    next >
Text File  |  1991-11-20  |  10KB  |  265 lines

  1.  
  2.  
  3. Introduction to Gofer         APPENDIX A: SUMMARY OF GRAMMAR                    
  4.  
  5.  
  6. APPENDIX A: SUMMARY OF GRAMMAR
  7.  
  8. This section gives a summary of the grammar for the  language  used  by
  9. Gofer.  The non-terminals <interp> and <module> describe the syntax  of
  10. expressions that can be entered into the Gofer interpreter and that  of
  11. files of definitions that can be loaded into Gofer respectively.
  12.  
  13. The following notational conventions are used in the Grammar  which  is
  14. specified using a variant of BNF:
  15.  
  16.   o <angle brackets> are used to distinguish names of nonterminals from
  17.     keywords.
  18.  
  19.   o vertical | bars  are used to separate alternatives.
  20.  
  21.   o {braces} enclose items which may be repeated zero or more times.
  22.  
  23.   o [brackets] are used for optional items.
  24.  
  25.   o (parentheses) are used for grouping.
  26.  
  27.   o "quotes" surround characters which might otherwise be confused with
  28.     the notations introduced above.
  29.  
  30. The following terminal symbols are used but not defined by the grammar:
  31.  
  32.   VARID    identifier beginning with lower case letter as described in
  33.            section 6.
  34.   CONID    like VARID, but beginning with upper case letter.
  35.   VAROP    operator symbol not beginning with a colon, as described in
  36.            section 6.
  37.   CONOP    constructor function operator, like VAROP, but beginning
  38.            with a colon character.
  39.   INTEGER  integer constant, as described in section 7.3.
  40.   FLOAT    floating point constant, as described in section 7.4.
  41.   CHAR     character constant, as described in section 7.5.
  42.   STRING   string constant, as described in section 7.7.
  43.  
  44.  
  45. Top-level grammar
  46. -----------------
  47.  
  48.     <module>   ::= "{" <topdecls> "}"               module
  49.  
  50.     <interp>   ::= <exp> [<where>]                  top-level expression
  51.  
  52.     <topdecls> ::= <topdecls>; <topdecls>           multiple declarations
  53.                 |  data <typeLhs> = <constrs>       datatype declaration
  54.                 |  type <typeLhs> = <type>          synonym declaration
  55.                 |  infixl [<digit>] <op> {, <op>}   fixity declarations
  56.                 |  infixr [<digit>] <op> {, <op>}
  57.                 |  infix  [<digit>] <op> {, <op>}
  58.                 |  primitive <prims> :: <type>      primitive bindings
  59.                 |  <class>                          class declaration
  60.                 |  <inst>                           instance declaration
  61.                 |  <decls>                          value declarations
  62.  
  63.  
  64.                                       93
  65.  
  66.  
  67.  
  68.  
  69. Introduction to Gofer         APPENDIX A: SUMMARY OF GRAMMAR                    
  70.  
  71.  
  72.     <typeLhs>  ::= CONID {VARID}                    type declaration lhs
  73.  
  74.     <constrs>  ::= <constrs> "|" <constrs>          multiple constructors
  75.                 |  <type> CONOP <type>              infix constructor
  76.                 |  CONID {<type>}                   constructor, n>=0
  77.  
  78.     <prims>    ::= <prims>, <prims>                 multiple bindings
  79.                 |  <var> <string>                   primitive binding
  80.  
  81. Type expressions
  82. ----------------
  83.  
  84.     <sigType>  ::= [<context> => ] <type>           [qualified] type
  85.  
  86.     <context>  ::= "(" [<pred> {, <pred>}] ")"      general form
  87.                 |  <pred>                           singleton context
  88.     <pred>     ::= CONID <type> {<type>}            predicate
  89.  
  90.     <type>     ::= <ctype> [ -> <type> ]            function type
  91.     <ctype>    ::= CONID {<atype>}                  datatype or synonym
  92.                 |  <atype>
  93.     <atype>    ::= VARID                            type variable
  94.                 |  "(" ")"                          unit type
  95.                 |  "(" <type> ")"                   parenthesised type
  96.                 |  "(" <type>,<type> {,<type>} ")"  tuple type
  97.                 |  "[" <type> "]"                   list type
  98.  
  99. Class and instance declarations
  100. -------------------------------
  101.  
  102.     <class>    ::= class [<context> =>] <pred> [<cbody>]
  103.     <cbody>    ::= where "{" <cdecls> "}"           class body
  104.     <cdecls>   ::= <cdecls>; <cdecls>               multiple declarations
  105.                 |  <var> {, <var>} :: <type>        member functions
  106.                 |  <fun> <rhs> [<where>]            default bindings
  107.  
  108.     <inst>     ::= inst  [<context> =>] <pred> [<ibody>]
  109.     <ibody>    ::= where "{" <idecls> "}"           instance body
  110.     <idecls>   ::= <idecls>; <idecls>               multiple declarations
  111.                 |  <fun> <rhs> [<where>]            member definition
  112.  
  113. Value declarations
  114. ------------------
  115.  
  116.     <decls>  ::= <decls>; <decls>                 multiple declarations
  117.               |  <var> {, <var>} :: <sigType>     type declaration
  118.               |  <fun> <rhs> [<where>]            function binding
  119.               |  <pat> <rhs> [<where>]            pattern binding
  120.  
  121.     <rhs>    ::= = <exp>                          simple right hand side
  122.               |  <gdRhs> {<gdRhs>}                guarded right hand sides
  123.  
  124.     <gdRhs>  ::= "|" <exp> = <exp>                guarded right hand side
  125.  
  126.     <where>  ::= where "{" <decls> "}"            local definitions
  127.  
  128.  
  129.  
  130.                                       94
  131.  
  132.  
  133.  
  134.  
  135. Introduction to Gofer         APPENDIX A: SUMMARY OF GRAMMAR                    
  136.  
  137.  
  138.     <fun>    ::= <var>                            function of arity 0
  139.               |  <pat> <varop> <pat>              infix operator
  140.               |  "(" <pat> <varop> ")"            section-like notation
  141.               |  "(" <varop> <pat> ")"
  142.               |  <fun> <apat>                     function with argument
  143.               |  "(" <fun> ")"                    parenthesised lhs
  144.  
  145. Expressions
  146. -----------
  147.  
  148.     <exp>    ::= \ <apat> {<apat>} -> <exp>       lambda expression
  149.               |  let "{" <decls> "}" in <exp>     local definition
  150.               |  if <exp> then <exp> else <exp>   conditional expression
  151.               |  case <exp> of "{" <alts> "}"     case expression
  152.               |  <opExp> :: <sigType>             typed expression
  153.               |  <opExp>
  154.     <opExp>  ::= <opExp> <op> <opExp>             operator application
  155.               |  <pfxExp>
  156.     <pfxExp> ::= - <appExp>                       negation
  157.               |  <appExp>
  158.     <appExp> ::= <appExp> <atomic>                function application
  159.               |  <atomic>
  160.     <atomic> ::= <var>                            variable
  161.               |  <conid>                          constructor
  162.               |  INTEGER                          integer literal
  163.               |  FLOAT                            floating point literal
  164.               |  CHAR                             character literal
  165.               |  STRING                           string literal
  166.               |  "(" ")"                          unit element
  167.               |  "(" <exp> ")"                    parenthesised expr.
  168.               |  (<exp> <op>)                     sections
  169.               |  (<op> <exp>)
  170.               |  "[" <list> "]"                   list expression
  171.               |  "(" <exp>, <exp> {, <exp>} ")"   tuple
  172.  
  173.     <list>   ::= [ <exp> {, <exp>} ]              enumerated list
  174.               |  <exp> "|" <quals>                list comprehension
  175.               |  <exp> ..                         arithmetic sequence
  176.               |  <exp, <exp> ..
  177.               |  <exp> .. <exp>
  178.               |  <exp>, <exp> .. <exp>
  179.     <quals>  ::= <quals>, <quals>                 multiple qualifiers
  180.               |  <pat> <- <exp>                   generator
  181.               |  <pat> = <exp>                    local definition
  182.               |  <exp>                            boolean guard
  183.  
  184.     <alts>   ::= <alts>, <alts>                   multiple alternatives
  185.               |  <pat> <altRhs> [<where>]         alternative
  186.     <altRhs> ::= -> <exp>                         single alternative
  187.               |  <gdAlt> {<gdAlt>}                guarded alternatives
  188.     <gdAlt>  ::= "|" <exp> -> <exp>               guarded alternative
  189.  
  190. Patterns
  191. --------
  192.  
  193.     <pat>    ::= <pat> <conop> <pat>              operator application
  194.  
  195.  
  196.                                       95
  197.  
  198.  
  199.  
  200.  
  201. Introduction to Gofer         APPENDIX A: SUMMARY OF GRAMMAR                    
  202.  
  203.  
  204.               |  <var> + <integer>                (n+k) pattern
  205.               |  <appPat>
  206.     <appPat> ::= <appPat> <apat>                  application
  207.               |  <apat>
  208.     <apat>   ::= <var>                            variable
  209.               |  <var> @ <pat>                    as pattern
  210.               |  ~ <pat>                          irrefutable pattern
  211.               |  _                                wildcard
  212.               |  <conid>                          constructor
  213.               |  INTEGER                          integer literal
  214.               |  CHAR                             character literal
  215.               |  STRING                           string literal
  216.               |  "(" ")"                          unit element
  217.               |  "(" <pat> ")"                    parenthesised expr.
  218.               |  (<pat> <conop>)                  sections
  219.               |  (<conop> <pat>)
  220.               |  "[" [ <pat> {, <pat>} ] "]"      list
  221.               |  "(" <pat>, <pat> {, <pat>} ")"   tuple
  222.  
  223. Variables and operators
  224. -----------------------
  225.  
  226.     <var>    ::= <varid>  |  "(" - ")"            variable
  227.     <op>     ::= <varop>  |  <conop>   |  -       operator
  228.  
  229.     <varid>  ::= VARID    |  "(" VAROP ")"        variable identifier
  230.     <varop>  ::= VAROP    |  ` VARID `            variable operator
  231.  
  232.     <conid>  ::= CONID    |  "(" CONOP ")"        constructor identifier
  233.     <conop>  ::= CONOP    |  ` CONID `            constructor operator
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.                                       96
  263.  
  264.  
  265.